<template>
	<view class="tolel">
<!-- 		<view class="mengbic" v-if="showimg==0" @click="closeFn">
			
		</view>
		<view class="imagw" v-if="showimg==0" @click="tiaozFn">
			<image src="https://medicine.sdshengyue.cn/uploads/images/20240105/20240105091525532312085.png" class="img-laba"></image>
		</view> -->
		<!-- <image src="../../static/images/sharee.png" class="share" mode="" @click="sharePage"></image> -->
	<!-- 	<view class="top" @click="gotoFn">
			<view class="top-top">
				<view class="top-top-left">
					<image class="gs" :src="qiye.qyimg" mode=""></image>
				</view>
				<view class="top-top-right">
					<view class="gs-name">
						{{qiye.qyname}}
					</view>
					<view class="gs-type">
						<view class="qi">
							<image src="../../static/images/qi.png" class="qiye" mode=""></image>
						</view>
						<view class="xiaow">
							小微企业
						</view>
					</view>
				</view>
			</view>
			<view class="top-bottom">
				{{qiye.qyxaingqing}}
			</view>
		</view> -->
		<view class="top" @click="gotoFn1">
					<view class="top-top">
						<view class="top-top-left">
							<image class="gs" :src="userInfo.avatar" mode=""></image>
						</view>
						<view class="top-top-right">
							<view class="gs-name">
								{{userInfo.nickname}}
							</view>
						</view>
					</view>
				</view>
		<view class="procure">
			<view class="procure-top">
				<view class="xian">

				</view>
				<view class="procure-top-title">
					采购
				</view>
			</view>
			<view class="procure-bottom">
				{{newsData.name}}
				<!-- 党参、北沙参、南沙参、麦冬、白前、泽泻、半夏、苍术、三棱、红景天、沙苑子、蕉丝子、王不留行、覆盆子、地肤子、酸枣仁、佛手、泽兰、金沸草、通草获神、乌梢蛇、蜂房、芒硝、五倍子、薪蛇、金养麦、阳起石、防己、竹茹、斑鸠、蟾酥 -->
			</view>
		</view>
		<view class="phone">
			<view class="procure-top">
				<view class="xian">

				</view>
				<view class="procure-top-title">
					联系方式
				</view>
			</view>
			<view class="phone-bottom">
				<view class="phone-bottom-item" v-for="(item,index) in newsData.contacts">
					<view class="phone-bottom-item-top">
						<image style="width: 80rpx; height: 80rpx;" src="../../static/images/toi.png" mode=""></image>
					</view>
					<view class="phone-bottom-item-bottom">
						<view class="people">
							{{item.name}}
						</view>
						<view class="tel">
							{{item.tel}}
						</view>
					</view>
				</view>
			</view>
		</view>
<!-- 		<view class="datail">
			<view class="procure-top">
				<view class="xian">
			
				</view>
				<view class="procure-top-title">
					详情信息
				</view>
			</view>
			<view class="datail-bottom">
				<view class="datail-bottom-item">
					
					<rich-text :nodes="goodsContentConv(newsData.ycxq)"></rich-text>
				</view>
			</view>
		</view> -->
		<view class="procure">
			<view class="procure-top">
				<view class="xian">
		
				</view>
				<view class="procure-top-title">
					详情信息
				</view>
			</view>
			<view class="procure-bottom">
				{{newsData.xqxx}}
				<!-- 党参、北沙参、南沙参、麦冬、白前、泽泻、半夏、苍术、三棱、红景天、沙苑子、蕉丝子、王不留行、覆盆子、地肤子、酸枣仁、佛手、泽兰、金沸草、通草获神、乌梢蛇、蜂房、芒硝、五倍子、薪蛇、金养麦、阳起石、防己、竹茹、斑鸠、蟾酥 -->
			</view>
		</view>
		<view class="datail">
			<view class="procure-top">
				<view class="xian">
			
				</view>
				<view class="procure-top-title">
					详情信息图片
				</view>
			</view>
			<view class="datail-bottom">
				<view class="datail-bottom-item">
					<image v-for="item in newsData.ycxq" :src="item" mode="aspectFill" class="datail-bottom-item-img" @click="yulan(item)"></image>
					<!-- <rich-text :nodes="goodsContentConv(newsData.ycxq)"></rich-text> -->
				<!-- 	<view class="" v-html="goodsContentConv(newsData.ycxq)">
						
					</view> -->
					<!-- <view class="" v-html="newsData.ycxq">
						
					</view> -->
				</view>
			</view>
		</view>
		<view class="bottom-gongneng">
			<view class="del" @click="show = true">
				<image class="img-del" src="../../static/images/del.png" mode=""></image>
				<view class="">
					删除
				</view>
			</view>
			<view class="bianji"  @click="bianjiFn">
				<image class="img-bianji" src="../../static/images/jianji.png" mode=""></image>
				<view class="">
					重新编辑
				</view>
			</view>
		</view>
		<view class="notification" v-if="show">
			<view class="notification-top">
				您确定要删除吗
			</view>
			<view class="notification-center">
			<!-- 	应国家法律法规要求，该业务需要核实您的身份 -->
			</view>
			<view class="notification-bottom">
				<view class="notification-bottom-left" @click="quxiaoFn">
					取消
				</view>
				<view class="notification-bottom-right" @click="delFn">
					确定
				</view>
			</view>
		</view>
		<view class="mengbi" v-if="show">
			
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { useUserStore } from '@/stores/user'
	import { ref } from 'vue'
	import { onShow,onLoad } from '@dcloudio/uni-app'
	import { storeToRefs } from 'pinia'
	import { getcaigDetail,getqiyeDetail,getcaidel } from '@/api/news'
	const userStore = useUserStore()
	const { userInfo, isLogin } = storeToRefs(userStore)
	const showimg=ref('')
	const show=ref(false)
	// let user_id=''
	const gotoFn1=()=>{
		uni.navigateTo({
			url:"/pages/collection/yonghu_detile?userId="+userId
		})
	}
	onShow(() => {
	    userStore.getUser()
		showimg.value=userInfo.value.qualifications
		console.log(showimg.value,'userInfo');
		getData(newsId)
		getqiye()
	})
	let newsId = ''
	let userId=''
	onLoad((options: any) => {
	    newsId = options.id
		userId=options.userId
		// console.log(userId,'userId');
	 //    getData(newsId)
		// getqiye()
	})
	// onShow(()=>{
	// 	getData(newsId)
	// 	getqiye()
	// })
	const yulan=(item)=>{
			wx.previewImage({
					urls: newsData.value.ycxq, //需要预览的图片http链接列表，多张的时候，url直接写在后面就行了
					current: item, // 当前显示图片的http链接，默认是第一个
					success: function (res) { },
		
				})
	}
	const quxiaoFn=()=>{
		show.value = false
	}
	const newsData = ref<any>({})
	const getData = async (id) => {
	    let aa = await getcaigDetail({ id })
		newsData.value=aa
			newsData.value.contacts=JSON.parse(newsData.value.contacts)
			newsData.value.ycxq=JSON.parse(newsData.value.ycxq)
	}
	const qiye=ref({})
	const getqiye=async()=>{
		qiye.value=await getqiyeDetail({
			user_id:userId
		})
		// console.log(data);
	}
	
	const gotoFn=()=>{
		uni.navigateTo({
			url:"/pages/collection/enterprise_details?userId="+userId
		})
	}
	
	const closeFn=()=>{
		showimg.value=1
	}
	const tiaozFn=()=>{
		uni.navigateTo({
			url:'/pages/user/member'
		})
	}
	const sharePage =()=>{
		const shareConfig={
			title:'果意园',
			path:'/pages/news_detail/news_detail'
		}
		 uni.share(shareConfig);
	}
	
	
	const bianjiFn=()=>{
		const params = encodeURIComponent(JSON.stringify(newsData.value));
		uni.navigateTo({
			url:"/pages/user/re_edit_procure?data="+params
		})
	}
	
	const delFn=async()=>{
		let a=await getcaidel({
			id:newsId
		})
		// console.log(a,'aaa');
		if(a.data==1){
			uni.showToast({
				title:"删除成功",
				icon:"none"
			})
		}
		setTimeout(()=>{
			 var pages = getCurrentPages(); // 当前页面
			var beforePage = pages[pages.length - 1]; 
			  wx.navigateBack({
			               success: function () {
			                 beforePage.onLoad(); // 执行前一个页面的onLoad方法，相当于刷新一次
			               }
			             })
		},2000)
		
	}
	const goodsContentConv=(html)=>{

	var GRT = [
						// img 样式
						['img', "max-width:100%;height:auto;"],
					];
					for (let i = 0; i < GRT.length; i++) {
						html = html.replace(new RegExp('<' + GRT[i][0] + '>|<' + GRT[i][0] + ' (.*?)>', 'gi'), function(word) {
							// 分析 dom 上是否带有 style=""
							if (word.indexOf('style=') != -1) {
								var regIn = new RegExp('<' + GRT[i][0] + '(.*?)style="(.*?)"(.*?)(/?)>', 'gi');
								return word.replace(regIn, '<' + GRT[i][0] + '$1style="$2 ' + GRT[i][1] + '"$3$4>');
							} else {
								var regIn = new RegExp('<' + GRT[i][0] + '(.*?)(/?)>', 'gi');
								return word.replace(regIn, '<' + GRT[i][0] + '$1 style="' + GRT[i][1] + '$2">');
							}
						});
					}
					return html;
		}
</script>

<style lang="scss" scoped>
	.mengbi {
		position: fixed;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		z-index: 33;
		background-color: rgba(0, 0, 0, 0.4);
	}
	.bottom-gongneng{
		height: 200rpx;
		position: fixed;
		bottom: 0;
		right: 0;
		left: 0;
		width: 100%;
		padding: 28rpx;
		display: flex;
		background-color: #fff;
		.del{
			// width: 200rpx;
			width: 30%;
			height: 84rpx;
			margin-right: 20rpx;
			background-color: #EE5151;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			display: flex;
			border-radius: 16rpx;
			line-height: 84rpx;
			// text-align: center;
			justify-content: center;
			 align-items: center;
			.img-del{
				width: 40rpx;
				height: 40rpx;
			}
		
		}
		.bianji{
			flex: 1;
			height: 84rpx;
			// width: ;
			display: flex;
			// line-height: ;
			background-color: #59C381;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			border-radius: 16rpx;
			line-height: 84rpx;
			// text-align: center;
			justify-content: center;
			align-items: center;
			.img-bianji{
				width: 40rpx;
				height: 40rpx;
				display: inline-block;
				justify-content: middle;
			}
		}
	}
	.mengbic{
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0,0,0,0.2);
	}
	.imagw{
		width: 750rpx;
		height: 730rpx;
		position: absolute;
		top: 274rpx;
		left: 50%;
		transform: translate(-50%,0);
	}
	.img-laba{
		width: 750rpx;
		height: 730rpx;
	}
	.share{
		width: 216rpx;
		height: 82rpx;
		position: fixed;
		right: 20rpx;
		bottom:260rpx;
	}
	.datail{
		margin-top: 48rpx;
		// margin-bottom: 50rpx;
		padding-bottom: 288rpx;
		.procure-top {
			padding-bottom: 16rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
			display: flex;
			border-bottom: 2rpx solid #F5F5F5;
			.xian {
				width: 6rpx;
				height: 28rpx;
				background: #19C181;
				border-radius: 6rpx 6rpx 6rpx 6rpx;
				opacity: 1;
				margin-top: 11rpx;
				margin-right: 8rpx;
			}
		
		}
		.datail-bottom{
			padding: 20rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			.datail-bottom-item{
				padding: 20rpx;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				opacity: 1;
				border: 2rpx solid #F5F5F5;
				text-align: center;
				.datail-bottom-item-img{
					width: 180rpx;
					height: 180rpx;
					margin-right: 3rpx;
				}
			}
		}
	}
	.tolel {
		width: 92%;
		margin-left: 4%;

		.top {
			background-color: #fff;
			height: 170rpx;
			padding: 28rpx;
			margin-top: 28rpx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;

			.top-top {
				display: flex;

				.top-top-left {
					.gs {
						width: 108rpx;
						height: 108rpx;
					}
				}

				.top-top-right {
					padding-left: 20rpx;
					flex: 1;

					.gs-name {
						font-size: 32rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						color: #333333;
						margin-bottom: 12rpx;
					}

					.gs-type {
						width: 144rpx;
						height: 38rpx;
						background: rgba(25, 194, 129, 0.05);
						border-radius: 4rpx 4rpx 4rpx 4rpx;
						opacity: 1;
						display: flex;
						justify-content: center;
						line-height: 38rpx;
						font-size: 22rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #19C281;

						.qi {
							display: inline-block;

							.qiye {
								width: 28rpx;
								height: 28rpx;
								vertical-align: middle;
							}
						}

					
					}

				}
			}

			.top-bottom {
				width: 100%;
				height: 66rpx;
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #AAAAAA;
				display: -webkit-box;
				/*弹性伸缩盒子模型显示*/
				-webkit-box-orient: vertical;
				/*排列方式*/
				-webkit-line-clamp: 2;
				/*显示文本行数*/
				overflow: hidden;
				/*溢出隐藏*/
			}
		}

		.procure {
			margin-top: 28rpx;
			// height: 380rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			padding: 20rpx;

			.procure-top {
				padding-bottom: 16rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #333333;
				display: flex;
				padding-bottom: 20rpx;
				border-bottom: 2rpx solid #F5F5F5;

				.xian {
					width: 6rpx;
					height: 28rpx;
					background: #19C181;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
					opacity: 1;
					margin-top: 11rpx;
					margin-right: 8rpx;
				}

			}

			.procure-bottom {
				padding: 20rpx;
				background: #F8F8F8;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				opacity: 1;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #777777;
				line-height: 33rpx;

			}

		}

		.phone {
			margin-top: 28rpx;
			// height: 380rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			padding: 20rpx;

			.procure-top {
				padding-bottom: 16rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #333333;
				display: flex;
				border-bottom: 2rpx solid #F5F5F5;
				.xian {
					width: 6rpx;
					height: 28rpx;
					background: #19C181;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
					opacity: 1;
					margin-top: 11rpx;
					margin-right: 8rpx;
				}

			}

			.phone-bottom{
				// margin-top: 20rpx;
				.phone-bottom-item{
					height: 80rpx;
					display: flex;
					margin-top: 20rpx;
					.phone-bottom-item-bottom{
						margin-left: 20rpx;
						.people{
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							color: #333333;
						}
						.tel{
							margin-top: 4rpx;
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #777777;
							
						}
					}
				}
			}
		}
	}
	.notification {
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		width: 614rpx;
		// height: 282rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		z-index: 43;
	
		.notification-top {
			text-align: center;
			margin-top: 36rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
	
		}
	
		.notification-center {
			text-align: center;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #999999;
			margin-top: 22rpx;
			margin-bottom: 34rpx;
	
		}
	
		.notification-bottom {
			display: flex;
			justify-content: space-evenly;
			text-align: center;
			align-items: center;
			border-top: 1rpx solid #EEEEEE;
			height: 126rpx;
		
			.notification-bottom-left {
				width: 40%;
				height: 70rpx;
				line-height: 70rpx;
				border-radius: 10rpx;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #333;
				background-color: #efefef;
		
			}
		
			.notification-bottom-right {
				width: 40%;
				height: 70rpx;
				line-height: 70rpx;
				border-radius: 10rpx;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #fff;
				background-color: #19C181;
		
			}
		}
	}
</style>